package com.leyou.item.web;

import com.leyou.item.pojo.SpecGroup;
import com.leyou.item.pojo.SpecParam;
import com.leyou.item.service.SpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wgc
 * @create 2019-06-15 19:14
 */
@RestController
@RequestMapping("spec")
public class SpecificationController {

    @Autowired
    private SpecificationService specificationService;
    /**
     * 根据分类id 查询规格组
     *
     * @param cid
     * @return
     */
    @GetMapping("group/{cid}")
    public ResponseEntity<List<SpecGroup>> queryGroupByCid(@PathVariable("cid") Long cid) {
        List<SpecGroup> list = specificationService.queryGroupByCid(cid);
        return ResponseEntity.ok(list);
    }

    @GetMapping("group/{gid}")
    public ResponseEntity<List<SpecParam>> queryParamByGid(@PathVariable("gid") Long gid) {
        List<SpecParam> list = specificationService.queryParamByGid(gid);
        return ResponseEntity.ok(list);
    }
    /**
     * 查询规格参数集合
     * @param gid
     * @return
     */
    @GetMapping("params")
    public ResponseEntity<List<SpecParam>> queryParamList(
            @RequestParam(value = "gid",required = false)Long gid,
            @RequestParam(value = "cid",required = false)Long cid,
            @RequestParam(value = "searching",required = false)Boolean searching
    ) {
        return ResponseEntity.ok(specificationService.queryParamList(gid,cid,searching));
    }
    }
